#!/usr/bin/env python
# -*- coding: utf-8 -*-

import MySQLdb

def connect(ip) :
	conn = MySQLdb.connect(ip, 'gamevil', 'vlwlrpaqlf', 'pz_user')
	csr  = conn.cursor()
	return (conn, csr)

connMap = {}
connMap["100"] = connect('172.16.1.181')
connMap["101"] = connect('172.16.1.182')
connMap["102"] = connect('172.16.2.31')
connMap["103"] = connect('172.16.2.32')
connMap["104"] = connect('172.16.2.33')
connMap["105"] = connect('172.16.2.34')

send_zen = 250
vc_index = 85

sql = """INSERT INTO data_mail(seq, send_user_seq, send_user_nickname, send_user_image_url, recv_user_seq, mail_status, gift_status, gift_vcindex, zen, gold, bag_type, bag_slot_number, stack_num, class_type, sub_type, tid, iconidx, item_type, cur_duration, max_duration, set_type, non_identity, cur_refine_step, quality, level, eff_type0, eff_pos0, eff_value0, eff_type1, eff_pos1, eff_value1, eff_type2, eff_pos2, eff_value2, eff_type3, eff_pos3, eff_value3, eff_type4, eff_pos4, eff_value4, eff_type5, eff_pos5, eff_value5, eff_type6, eff_pos6, eff_value6, open_upgrade_stone_slot, ablity_enhance_rate, max_enhance_step, buy_use, evolve_step, evolve_max, evolve_point, evolve_eff, evolve_eff_value, message, send_date) VALUES (NULL, 0, "GAMEVIL", "", %d, 0, 2, %d, %d, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "특별 선물!! 더욱 더 노력하는 제노니아 온라인이 되겠습니다.", UNIX_TIMESTAMP())"""

send_count = 0

fd = open("reward_userlist.txt")
for line in fd.xreadlines() :
	user_seq, shard_type = line.strip().split(",")

	user_seq = user_seq.strip()
	shard_type = shard_type.strip()

	conn, csr = connMap.get(shard_type)
	exec_sql = sql % (int(user_seq), vc_index, send_zen)
	csr.execute(exec_sql)
	send_count += 1
	if (send_count % 1000 == 0) :
		print "%d user send complete.." % send_count
fd.close()

print "total %d user send complete!" % send_count

for shard_type in connMap.keys() :
	print "close... %s" % shard_type
	conn, csr = connMap.get(shard_type)
	conn.commit()
	csr.close()
	conn.close()
